<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>密码修改</title>
</head>
<body class="layui-layout-body">
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div class="body_right">
        <h4 class="nav_title">账户设置</h4>
         <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
	        <ul class="layui-tab-title">
	            <li lay-id="EDIT_INFO">个人信息修改</li>
	            <li class="layui-this">密码重置</li>
	        </ul>
	        <div class="layui-tab-content" >
        		<div class="layui-tab-item layui-show">
        		
        				<form class="layui-form">
			                <div class="layui-form-item">
			                    <label class="layui-form-label">原始密码</label>
			                    <div class="layui-input-inline">
			                        <input type="password" id="currentPassword" name="currentPassword" required="" lay-verify="currentPassword" placeholder="请输入密码" autocomplete="off" class="layui-input">
			                    </div>
			                </div>
			                <div class="layui-form-item">
			                    <label class="layui-form-label">新密码</label>
			                    <div class="layui-input-inline">
			                        <input type="password" id="newPassword" name="newPassword" required="" lay-verify="newPassword" placeholder="请输入密码" autocomplete="off" class="layui-input">
			                    </div>
			                </div>
			                <div class="layui-form-item">
			                    <label class="layui-form-label">确认密码</label>
			                    <div class="layui-input-inline">
			                        <input type="password" id="confPassword" name="confPassword" required="" lay-verify="confPassword" placeholder="请输入密码" autocomplete="off" class="layui-input">
			                    </div>
			                </div>
			                
			                <div class="layui-form-item">
			                    <label class="layui-form-label"></label>
			                    <div class="layui-input-inline">
			                        <button  class="layui-btn" lay-filter="add" lay-submit="">确认修改</button>
			                    </div>
			                </div>
			            </form>
        		
        		</div>
        	</div>
         </div>
    </div>
</div>
 <script>
        layui.use(['form','layer','element'], function(){
            $ = layui.jquery;
          var form = layui.form,element=layui.element
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            currentPassword: function(value){
              if(!value){
                return '请输入原始密码';
              }
            },
            newPassword: [/(.+){6,12}$/, '密码必须6到12位'],
            
            confPassword: function(value){
                if($('#confPassword').val()!=$('#newPassword').val()){
                    return '两次密码不一致';
                }
            }
          });
          
          element.on('tab(docDemoTabBrief)', function(elem){
		  		var id = $(this).attr('lay-id');
		  		if(id == 'EDIT_INFO'){
		  		 	location.href='/admin/personal/info.htm';
		  		}
		  });

          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            
            $.ajax({
      			type:"POST", 
      			url:"/admin/operator/modifyPassword.htm",
      			data:data.field,
      			success:function(result) {
		      
		      		if(result.code=='1'){
		      			layer.alert("密码修改成功,请重新登录", {icon: 6},function () {
			                // 获得frame索引
			                 location.href="/admin/login.htm";
			            });
		      		}else{
		      		 	layer.msg(result.msg);
		      		}
		      
		    	 	} 
		    }); 
            
            return false;
          });
          
        });
    </script>
</body>
</html>